import { TextNode, TextNodeModel, NodeConfig, GraphModel } from '@logicflow/core'
import { getBpmnId } from '../getBpmnId'
class TextTaskModel extends TextNodeModel {
  static extendKey = 'TextTaskModel'
  constructor(data: NodeConfig, graphModel: GraphModel) {
    if (!data.id) {
      data.id = `textTask_${getBpmnId()}`
    }
    if (!data.text) {
      data.text = ''
    }
    if (data.text && typeof data.text === 'string') {
      data.text = {
        value: data.text,
        x: data.x,
        y: data.y + 2,
      }
    }
    super(data, graphModel)
    this.rx = 80
    this.ry = 45
  }
  getTextStyle() {
    const style = super.getTextStyle()
    style.color = '#e68245'
    style.fontSize = 16
    return style
  }
}

class TextTaskView extends TextNode {
  static extendKey = 'TextTaskNode'
}

const TextTask = {
  type: 'bpmn2:textTask',
  view: TextTaskView,
  model: TextTaskModel,
}

export { TextTaskView, TextTaskModel }
export default TextTask
